﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using _DataProvider;

public partial class Admin_Parts_XemDSGD : System.Web.UI.UserControl
{
    private SqlConnection connSql;
    protected void Page_Load(object sender, EventArgs e)
    {
        DataTable dt = GetDSGD();
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }

    public DataTable GetDSGD()
    {
        DataProvider dt = new DataProvider();
        connSql = dt.connect();
        SqlDataAdapter daDepart = null;
        daDepart = new SqlDataAdapter("SELECT * FROM GiaoDich ORDER BY TransID DESC", connSql);
        DataSet ds = new DataSet();
        daDepart.Fill(ds);
        return ds.Tables[0];
    }

    public DataTable GetDSGDTheoTT(int State)
    {
        DataProvider dt = new DataProvider();
        connSql = dt.connect();
        SqlDataAdapter daDepart = null;
        if (State == 4)
        {
            daDepart = new SqlDataAdapter("SELECT * FROM GiaoDich ORDER BY TransID DESC", connSql);
        }
        else
        {
            daDepart = new SqlDataAdapter("SELECT * FROM GiaoDich where State = '" + State + "' ORDER BY TransID DESC", connSql);
        }
        DataSet ds = new DataSet();
        daDepart.Fill(ds);
        return ds.Tables[0];
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = GetDSGDTheoTT(int.Parse(DropDownList1.SelectedValue.ToString()));
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridViewRow gr = GridView1.SelectedRow;
        if (gr.Cells[4].Text == "1")
        {
            Response.Redirect("~/admin/XemCTGD.aspx?TransID=" + gr.Cells[1].Text);
        }
        else
        {
            Response.Write("<script>alert('Chưa được NXB chấp nhận')</script>");
        }
    }
}